package com.smzd.ccms.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smzd.ccms.dao.SiteChannelConfigDao;
import com.smzd.ccms.domain.Channel;
import com.smzd.ccms.domain.SiteChannelConfig;
import com.smzd.ccms.domain.SysDict;
import com.smzd.core.dao.IDao;
import com.smzd.framework.core.business.AbstractFGService;
import com.smzd.framework.utils.db.FGRowConverter;

@Service
public class SiteChannelConfigService extends AbstractFGService<SiteChannelConfig> {
    @Autowired
    private SiteChannelConfigDao dao;
    
    @Override
    protected IDao<SiteChannelConfig> getDao() {
        return dao;
    }
    
    @Override
    public FGRowConverter<SiteChannelConfig> getConverter() {
        return converter;
    }

    private static FGRowConverter<SiteChannelConfig> converter = new FGRowConverter<SiteChannelConfig>() {
        @Override
        public Object[] convert(SiteChannelConfig elem) {
            SysDict sysDict = elem.getSysDict();
            Object[] obj_sysDict;
            if(sysDict==null){
                obj_sysDict = null;
            }else{
                Integer id_sysDict = sysDict.getId();
                String name_sysDict = sysDict.getName();
                obj_sysDict = new Object[]{id_sysDict, name_sysDict};
            }
            Channel channel = elem.getChannel();
            Object[] obj_channel;
            if(channel==null){
                obj_channel = null;
            }else{
                Integer id_channel = channel.getId();
                String name_channel = channel.getName();
                obj_channel = new Object[]{id_channel, name_channel};
            }
            Object[] fs = new Object[]{
                    elem.getId(),
                    elem.getName(),
                    elem.getDescription(),
                    obj_sysDict,
                    obj_channel
                };
                return fs;
        }
    };

	/**
	 * 这个方法目前只用在了首页配置上。
	 * 
	 * @param meetingId
	 * @param dictId
	 * @return
	 */
	public SiteChannelConfig getSiteChannelConfig(int meetingId, int dictId) {
		return dao.getSiteChannelConfig(meetingId, dictId);
	}

	/**
	 * 查找指定的字典表配置是否配置到了指定的站点的指定栏目上。<br>
	 * 不论disabled为何值，都返回其对象（如果有）。
	 * 
	 * @param id
	 * @param dictId
	 * @param chId
	 * @return
	 */
	public SiteChannelConfig getSiteChannelConfig(int meetingId, int dictId, int chId) {
		return dao.getSiteChannelConfig(meetingId, dictId, chId);
	}

	public void toggleDisabled(SiteChannelConfig schcfg) {
		dao.toggleDisabled(schcfg);
	}
   
}